package org.bootstrap.controller;

import cn.hutool.core.lang.Console;
import cn.hutool.json.JSONObject;
import org.bootstrap.response.ResponseBody;
import org.bootstrap.service.Impl.ListServiceImpl;
import org.bootstrap.service.Impl.UserServiceImpl;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.LinkedList;

@RestController
@CrossOrigin
@RequestMapping(value = "list")
@SuppressWarnings("unused")
public class ListController {
    @Resource
    private ListServiceImpl listService;

    @Resource
    private ResponseBody responseBody;

    @GetMapping("/parent")
    public JSONObject get_detail(@PathParam("id") String id, @PathParam("page") String page) {
        return listService.get_detail(id, page);
    }

    @GetMapping("/parent/sel_options")
    public LinkedList<HashMap<String, Object>> get_sel_options() {
        return listService.get_sel_options();
    }

    @PostMapping(value = "parent/push")
    public JSONObject push(@RequestBody(required = false) HashMap<String, Object> _form) {
        return listService.push(_form);
    }

    // 单子富文本插入
    @PostMapping(value = "children/content_push")
    public JSONObject rt_push(@RequestParam(required = false, value = "list_id") String list_id, @RequestParam(value = "content", required = false) String content) {
        return listService.content_push(list_id, content);
    }

    // 单子富文本图片上传
    @PostMapping(value = "children/img_push")
    public JSONObject rt_img_push(@RequestParam(value = "file_list", required = false) MultipartFile[] file_list) {
        return listService.rt_img_push(file_list);
    }

    // 查询子单 上下关联 id 父级单号
    @GetMapping("children")
    public JSONObject get_children(@PathParam("id") String id) {
        return listService.get_children(id);
    }

    // 获取子单的工作类型
    @PostMapping("children/work_type")
    public JSONObject get_children_work_type() {
        return listService.get_children_work_type();
    }

    // 添加子单
    @PostMapping("children/push")
    public JSONObject add_children(@RequestBody(required = false) HashMap<String, Object> params) {
        return listService.add_children(params);
    }

    // 子单详情
    @GetMapping("children/detail")
    public HashMap<String, Object> get_children_detail(@PathParam("id") String id) {
        return listService.get_children_detail(id); // 此处id 为单号 不是self_id;
    }
}
